package project.newCode.scenegraph;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import project.hulpPakket.Matrix4f;
import project.newCode.transformations.Transformation;

public class CompositeTransform implements Component{

	private List<Component> components = new ArrayList<Component>();
	private Transformation transform;
	
	public CompositeTransform(Transformation t) {
		transform = t;
	}
	@Override
	public void enter(SceneTraverser t) {
		t.visitEntry(this);
		for (Component component : components) {
			component.enter(t);
		}
		leave(t);
	}

	@Override
	public void leave(SceneTraverser t) {
		t.visitLeave(this);
		// Moeten alle components hier ook leaven?
		
	}
	
	public void add(Component component) {
		components.add(component);
	}
	
	public void remove(Component component) {
		components.remove(component);
	}
	
	public List<Component> getComponents() {
		return components;
	}
	
	public Component getComponent(int index) {
		return components.get(index);
	}
	
	public Iterator<Component> iterator() {
		return new compIterator();
	}
	
	class compIterator implements Iterator<Component> {
		int currentIndex = 0;

		@Override
		public boolean hasNext() {
			if (currentIndex >= components.size()) {
				return false;
			} else {
				return true;
			}
		}

		@Override
		public Component next() {
			return components.get(currentIndex++);
		}

		@Override
		public void remove() {
			components.remove(--currentIndex);
		}

	}

	public Transformation getTransform() {
		return transform;
	}
	public void setTransform(Transformation transform) {
		this.transform = transform;
	}

	public String toString() {
		return "Transformnode: "+transform.getClass().toString();
	}
}
